package com.fjnu.dao.impl;

import com.fjnu.annotation.Cacheable;
import com.fjnu.annotation.QueryPerformanceMonitor;
import com.fjnu.dao.UserDao;
import com.fjnu.model.User;
import jdk.jfr.Registered;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 * @desc:
 * @author:
 * @date:
 */
@Repository
public class UserDaoImpl implements UserDao {
//    @Autowired
//    private Connection connection ;
    @Override
    public int insert(User user) {
        return 0;
    }

    @Override
    public int delete(String userId) {
        return 0;
    }

    @Override
    public int updateById(String userId, User newUser) {
        return 0;
    }

    @Override
    public int updatePasswordById(String userId, String oldPassword, String newPassword) {
        return 0;
    }

    @Cacheable
    @QueryPerformanceMonitor(expireTime = 1000)
    @Override
    public User selectById(String userId) {
        try {
            Thread.sleep(2000);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new User();
    }

    @Cacheable(needed = false)
    @Override
    public User selectByUsernameAndPassword(String username, String password) {
        return null;
    }

    @Override
    public int selectCount() {
//
//        String sql =  "SELECT count(*) from tb_user" ;
//        try {
//            PreparedStatement ps = connection.prepareStatement(sql);
//            ResultSet rs = ps.executeQuery();
//            if (rs.next()) {
//                return rs.getInt(1);
//            }
//        }catch (Exception e) {
//            throw new RuntimeException(e.getMessage()) ;
//        }
        return 0 ;

    }
    /**
     * 注入 connection Bean,利用connection bean来完成对数据库的操作
     */



}
